package cas.ihep.util;

/**
 * Created by chocolate on 2017/11/24.
 */
/*import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapred.JobConf;
//import org.apache.hadoop.mapred.JobHistory;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobStatus;
import org.apache.hadoop.mapred.TaskReport;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.PathFilter;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.http.HtmlQuoting;

public class JobReport{
    //    public void PrintJobStatus(){
//        Configuration conf = new Configuration();
//        conf.set("mapred.job.tracker", "hadoop06.ihep.ac.cn:8021");
//
//        JobClient client = new JobClient(new JobConf(conf));
//
//        JobStatus[] jobStatuses = client.getAllJobs();
//        System.out.println("jobstatues num:" + jobStatuses.length);
//        for (JobStatus jobStatus : jobStatuses) {
//
//            long lastTaskEndTime = 0L;
//
//            TaskReport[] mapReports = client.getMapTaskReports(jobStatus.getJobID());
//            for (TaskReport r : mapReports) {
//                if (lastTaskEndTime < r.getFinishTime()) {
//                    lastTaskEndTime = r.getFinishTime();
//                }
//            }
//
//            TaskReport[] reduceReports = client.getReduceTaskReports(jobStatus.getJobID());
//            for (TaskReport r : reduceReports) {
//                if (lastTaskEndTime < r.getFinishTime()) {
//                    lastTaskEndTime = r.getFinishTime();
//                }
//            }
//            client.getSetupTaskReports(jobStatus.getJobID());
//            client.getCleanupTaskReports(jobStatus.getJobID());
//
//            System.out.println("JobID: " + jobStatus.getJobID().toString() +
//                    ", username: " + jobStatus.getUsername() +
//                    ", startTime: " + jobStatus.getStartTime() +
//                    ", endTime: " + lastTaskEndTime +
//                    ", Durration: " + (lastTaskEndTime - jobStatus.getStartTime()));
//        }
//    }
    public static void main(String[] args) throws Exception {
        PathFilter jobLogFileFilter = new PathFilter() {
            final String user = "";
            final String jobname = "";

  //          final String uqUser = JobHistory.JobInfo.encodeJobHistoryFileName(
                    HtmlQuoting.unquoteHtmlChars(user));
            final String uqJobname = JobHistory.JobInfo.encodeJobHistoryFileName(
                    HtmlQuoting.unquoteHtmlChars(jobname));
            private boolean matchUser(String fileName) {

                return "".equals(uqUser) || uqUser.equals(fileName.split("_")[5]);
            }

            private boolean matchJobName(String fileName) {

                return "".equals(uqJobname) || fileName.split("_")[6].toLowerCase().contains(uqJobname);
            }

            public boolean accept(Path path) {
                return !(path.getName().endsWith(".xml")) && matchUser(path.getName()) && matchJobName(path.getName());
            }
        };
        String historyLogDir = "file:///var/log/hadoop-0.20/history/done";
        FileSystem fs = new Path(historyLogDir).getFileSystem(new Configuration());
        Path[] jobFiles = FileUtil.stat2Paths(fs.listStatus(new Path(historyLogDir), jobLogFileFilter));
        System.out.println("jobFiles num:" + jobFiles.length);
    }
}

*/